package com.seven.webhook.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gs.cd.cloud.common.ApiResult;
import com.seven.webhook.config.mybatis.SpecialCharactersInterceptor;
import com.seven.webhook.model.MonitorEmail;
import com.seven.webhook.service.MonitorEmailService;
import com.seven.webhook.utils.specification.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author seven
 * @since 2020-11-12
 */
@RestController
@RequestMapping("/webhook/monitorEmail")
public class MonitorEmailController extends
        AbstractController<MonitorEmail, MonitorEmailService> {

    /**
     * 批量添加or修改
     */
    @PostMapping("saveOrUpdate/many")
    public ApiResult saveMany(@RequestBody List<MonitorEmail> monitorEmail) {
        boolean b = iService.saveOrUpdateBatch(monitorEmail);
        return b ? ApiResult.success() : ApiResult.error();
    }

    /**
     * 通过 ruleId 删除
     */
    @DeleteMapping("delete/ruleId/{ruleId}")
    public ApiResult deleteByRuleId(@PathVariable String ruleId) {
        boolean remove = iService.remove(new QueryWrapper<MonitorEmail>().lambda()
                .eq(MonitorEmail::getRuleId, ruleId));
        return remove ? ApiResult.success() : ApiResult.error();
    }

    /**
     * 通过 ruleId获取
     */
    @GetMapping("get/ruleId/{ruleId}")
    public ApiResult getRuleId(@PathVariable String ruleId) {
        List<MonitorEmail> monitorEmailList = iService.getByRuleId(ruleId);
        return ApiResult.success(monitorEmailList);
    }


}

